package xiaolong.zhou.spring_demo.Config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import xiaolong.zhou.spring_demo.Interceptor.LoginCheck;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginCheck loginCheck;
    /**
     * 解决跨域问题
     * @param corsRegistry
     */
    @Override
    public void addCorsMappings(CorsRegistry corsRegistry){
        corsRegistry.addMapping("/**")
                .allowedOrigins("*")
                .allowedHeaders("*")
                .allowedMethods("*")
                .allowedOriginPatterns("*")
                .maxAge(3600);
    }
    @Override
    public void  addInterceptors(InterceptorRegistry registry){
        //"/home/user/captcha","home/user/send_email"
        registry.addInterceptor(loginCheck).addPathPatterns("/**").excludePathPatterns("/home/login","/home/register","/home/register/*");
    }



}
